package com.neulogistics.contrib.procuredcenter.api.application.command.handler;

import com.blackto.lib.mediat.unicast.IRequestHandler;
import com.neulogistics.contrib.procuredcenter.api.application.command.CreateGoodsListCommand;
import com.neulogistics.contrib.procuredcenter.domain.model.aggregate.GoodsList;
import com.neulogistics.contrib.procuredcenter.domain.repository.IGoodsListRepository;
import com.neulogistics.infrastructure.common.serviceresult.BaseResponse;
import com.neulogistics.infrastructure.common.serviceresult.ResultUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class CreateGoodsListCommandHandler implements IRequestHandler<CreateGoodsListCommand, BaseResponse<String>> {
    @Resource
    IGoodsListRepository goodsListRepository;

    @Override
    public BaseResponse<String> handle(CreateGoodsListCommand command) throws Exception {
        GoodsList goodsList = new GoodsList(command.listName, command.listDescription);
        goodsListRepository.save(goodsList);

        return ResultUtils.success(goodsList.getListId().toString());
    }
}
